# @Time    : 2018/5/30 19:36
# @Author  : Jame
from conf import setting
import pickle,os



def select(name,role):
    path=os.path.join(setting.DB_DIR,role,name)
    if os.path.exists(path):
        with open(path,'rb') as f:
            return pickle.load(f)
    else:
        return False



def save(obj):
    path=os.path.join(setting.DB_DIR,obj.__class__.__name__.lower()) #teacher/admin/student类的对象保存目录！
    if not os.path.exists(path):
        os.mkdir(path)

    path_file=os.path.join(path,obj.name) #obj.name为每个对象的名字
    with open(path_file,'wb') as f:
        pickle.dump(obj,f)
        f.flush()
